package j01set;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;

public class J1 {
    public static void main(String[] args) {
        HashSet<String> h1 = new HashSet<>();
        h1.add("hello");
        h1.add("word");
        h1.add("lanou");
        h1.add("huashan");
        h1.add("bb");
        h1.add("aa");
        h1.add("cc");
        h1.add("aa");
        System.out.println("h1 = " + h1);

        System.out.println("======");
        ArrayList<Integer> arr1 = new ArrayList<>();
        arr1.add(12);
        arr1.add(12);
        arr1.add(13);
        System.out.println("arr1 = " + arr1);

        HashSet<Integer> h2 = new HashSet<>(arr1);
        System.out.println("h2 = " + h2);

        ArrayList<Integer> arr2 = new ArrayList<>(h2);
        System.out.println("arr2 = " + arr2);
    }
}

class J2size{
    public static void main(String[] args) {
        //16 - 16*0.75=12
        //容量翻倍  32
        //32*0.75=24
        HashSet<Integer> h1= new HashSet<>(16,0.75f);
        h1.add(34);
        //...

        System.out.println(h1.contains(34));//?

        System.out.println("====");
        class Cat{
            String name;

            public Cat(String name) {
                this.name = name;
            }
        }
        HashSet<Cat> catArr = new HashSet<>();
        catArr.add(new Cat("bosi"));
        catArr.add(new Cat("bosi"));
        System.out.println("catArr = " + catArr);
        System.out.println(catArr.contains(new Cat("bosi")));//false
        System.out.println(catArr.size());
    }
}
class J3for{
    public static void main(String[] args) {
        HashSet<String> arr = new HashSet<>();
        arr.add("qq");
        arr.add("ww");
        arr.add("dd");
        arr.add("鑫峰");
        arr.add("dd");
        for (String temp :
                arr) {
            System.out.println(temp);
        }
        Iterator<String> it = arr.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }


    }
}